# for NO!RE74

rm(list=ls())
library(Matching)

# This sources in a function that creates the right model for propensity score matching & MatchBalance

load(file="rep.sourcecode.nore74cps1.RData")

X.Bal <- as.matrix(cbind(
                         foo$age,
                         foo$educ,
                         foo$black,
                         foo$hispan,
                         foo$married,
                         foo$nodegree,
                         I(foo$re75/1000),
                         I((foo$re75/1000)^2),
                         I(foo$hispan*foo$educ),
                         I((foo$age)^2),
                         I((foo$educ)^2),
                         I((foo$black)^2),
                         I((foo$hispan)^2),
                         I((foo$married)^2),
                         I((foo$nodegree)^2),
                         I((foo$re75/1000)^2),
                         I(foo$age*foo$educ),
                         I(foo$age*foo$black),
                         I(foo$age*foo$hispan),
                         I(foo$age*foo$married),    
                         I(foo$age*foo$nodegree),
                         I(foo$age*(foo$re75/1000)),
                         I(foo$educ*foo$black),
                         I(foo$educ*foo$married),    
                         I(foo$educ*foo$nodegree),
                         I(foo$educ*(foo$re75/1000)),
                         I(foo$black*foo$hispan),
                         I(foo$black*foo$married),
                         I(foo$black*foo$nodegree),
                         I(foo$black*(foo$re75/1000)),
                         I(foo$hispan*foo$married),
                         I(foo$hispan*foo$nodegree),
                         I(foo$hispan*(foo$re75/1000)),
                         I(foo$married*foo$nodegree),
                         I(foo$married*(foo$re75/1000)),
                         I(foo$nodegree*(foo$re75/1000))                        
                         ))
X <- X.Bal[,1:9]

sv <- c(9.240000e+02, 2.110000e+02, 5.500000e+02, 7.940000e+02, 4.660000e+02, 3.190000e+02, 1.030000e+02, 8.820000e+02, 2.430000e+02)

genout <- GenMatch(Tr = foo$treat, X = X, BalanceMatrix = X.Bal,
                   starting.values=sv,
                   pop.size = 1, wait.generations = 1,
                   max.generations = 1,
                   hard.generation.limit=TRUE)

m1 <- Match(Y=foo$re78, Tr=foo$treat, X=X, Weight.matrix=genout)
summary(m1)


